# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.

import requests

from .base import flatten, url_test

# supported locales
LOCALES = [
    "ar",
    "ast",
    "bg",
    "ca",
    "cs",
    "de",
    "dsb",
    "el",
    "en-GB",
    "en-US",
    "es-CL",
    "es-ES",
    "fr",
    "fy-NL",
    "gd",
    "it",
    "ja",
    "ko",
    "nl",
    "pt-BR",
    "pt-PT",
    "ru",
    "sco",
    "sv-SE",
    "ta",
    "tr",
    "uk",
    "zh-CN",
    "zh-TW",
]

# List of some locale name variants including unsupported short names and
# obsolete ab-CD-style names, which could be included in the visitors'
# Accept-Language HTTP header and should be redirected to the respective
# canonical locales
LOCALE_VARIANTS = {
    # have to make this en-XX so that it won't be a real locale we eventually
    # support. We now have en-{US,CA,ZA,GB}. See bug 1457959.
    "en-US": ["en", "en-XX"],
    "es-ES": ["es", "es-419"],
    "fr": ["fr-FR"],
    "ja": ["ja-JP-mac"],
    "pt-BR": ["pt"],
    "ta": ["ta-LK"],
    "zh-TW": ["zh-Hant", "zh-Hant-TW"],  # Bug 1263193
}

_urls = []
for locale in LOCALES:
    variants = [locale]
    variants.extend(LOCALE_VARIANTS.get(locale, []))
    for variant in variants:
        # check the landing page redirects for each locale variant
        _urls.append(url_test("/", f"/{locale}/", req_headers={"Accept-Language": variant}, status_code=requests.codes.found))

URLS = flatten(_urls)
